<?php
	include('header.php');
	//phpinfo();
	//newLine(4);
	//$aa = session_pagestart($_REQUEST["sid"]);
	//print_r($aa);
	$template->set_filenames(array(
		'index_body'=>'index_body.tpl'
	));
	
	if ( getModEnabled('News') )
	{
		$tid = getVar('tid');
		/* lay cac bai viet cua tat ca cac topic co position la center, xep theo tt giam dan va dang o trang thai hien thi */
		if ( empty($tid) )
			$sql = "SELECT * FROM topic WHERE tshow=1 ORDER BY orderby DESC";
		else
			$sql = "SELECT * FROM topic WHERE tshow=1 AND tid=$tid";
		$rs = $link->Execute($sql);
	
		$str = '';
		
		$template->assign_vars(array(
			'T_SITENAME' => $info['sitename'],
			'T_CHARSET' => $info['charset'],
			'T_STYLE_PATH' => $info['style_path'],
			'T_IMAGE_PATH' => $info['template_image_path'],
			'_LLL' => $_SESSION['cur_lang']
		));	
		
		while ( !$rs->EOF )
		{
			if ( $rs->fields('numrecordshow') == 0 )
				$record_show=$rs->RecordCount();
			else
				$record_show = $rs->Fields('numrecordshow');
			/* hien thi cac bai viet cua chu de hien tai trong recordset */
			$sql = "SELECT * FROM article WHERE tid=" . $rs->Fields('tid') . " ORDER BY datepost DESC,autoid desc LIMIT 0,$record_show";
		
			$rs_a = $link->Execute($sql);
	
			if ( !$rs_a->EOF )
			{
				$template->assign_block_vars('topic',array(
					'T_INDEX_TOPICNAME' => $rs->fields('tname_' . $_SESSION['cur_lang'])
				));	
				if ( trim($rs->fields('icon')) != '' )
					$template->assign_block_vars('topic.have_topic_icon',array(
						'T_INDEX_TOPICICON' => $rs->fields('icon')
					));
				$auto = 0;
				//MAIN CONTENT
				while ( !$rs_a->EOF && $auto < $rs->fields('num_show_full') )
				{
					$str = '';
					if ( ++$auto % 2 == 0 )	$clr = "#F0F0F0";
					else $clr = "transparent";
					
					if ( $rs_a->fields('picture') == 0 )
						$str .= $rs_a->fields('short_content_' . $_SESSION['cur_lang']);
					else
					{
						$str .= '<img src="images.php?imgid=' . $rs_a->fields('picture') . '" border="0" align="top" style="position: fixed; float: left" vspace="10" hspace="10">';
						$str .= $rs_a->fields('short_content_' . $_SESSION['cur_lang']);
					}
														
					$template->assign_block_vars('topic.main',array(
						'T_INDEX_MAIN_VIEWLINK' => setURLParams('act=dyn&mod=News&f=viewarticle&aid=' . $rs_a->fields('autoid')),
						'T_INDEX_MAIN_ROWCOLOR' => $clr,
						'T_INDEX_MAIN_NEWSTITLE' => $rs_a->fields('title_' . $_SESSION['cur_lang']),
						'T_INDEX_MAIN_NEWSCONTENT' => $str
					));
					
					if ( $rs_a->fields('datepost') == date('Y-m-d') )			
						$template->assign_block_vars('topic.main.main_new_news',array(
							'T_INDEX_MAIN_NEWNEWS' => $info['template_image_path'] . 'new.gif'
						));
													
					$rs_a->MoveNext();
				}
				/* SUB CONTENT */
				while ( !$rs_a->EOF )
				{
					$template->assign_block_vars('topic.sub',array(
						'T_INDEX_SUB_CONTENTLINK' => setURLParams('act=dyn&mod=News&f=viewarticle&aid=' . $rs_a->fields('autoid')),
						'T_INDEX_SUB_NEWSTITLE' => $rs_a->fields('title_' . $_SESSION['cur_lang'])
					));
	
					if ( $rs_a->fields('datepost') == date('Y-m-d') )			
						$template->assign_block_vars('topic.sub.sub_new_news',array(
							'T_INDEX_SUB_NEWNEWS' => $info['template_image_path'] . 'new.gif'
						));
					
					$rs_a->MoveNext();
				}
			}
			else
				if ( !empty($tid) )
					showMsg('Chưa có dữ liệu, Bạn vui lòng quay lại sau...','info','center');
			$rs_a->Close();
		
			$rs->MoveNext();
		}	/* end while rs */
	}
	else
	{
		$template->assign_block_vars('modEnabled',array(
			'_NEWS_STATUS' => 'Thông báo và tin tức đang được cập nhật !'
		));	
	}
	$template->pparse('index_body');
	
	include('footer.php');
?>
